#if UNITY_EDITOR

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

public class Editor_ASTC{
    const string _tag = "Editor_HybridCLR";

    [MenuItem("Tools/U3dCore/png格式转换/ASTC --> ETC")]
    static void Start(){
        Start333(false);
    }

    static void Start333(bool isASTC){
        var filrArr = Directory.GetFiles($"", "*.png", SearchOption.AllDirectories);

        for(int i2 = 0; i2 < filrArr.Length; i2++){
            var assetPath = filrArr[i2];
            var texture = AssetImporter.GetAtPath(assetPath); //通过路径得到资源
            SaveTexInfo((TextureImporter)texture, assetPath, isASTC);
        }
    }

    public static void SaveTexInfo(TextureImporter texture, string assetPath, bool isASTC){
        if(texture == null){
            Debug.LogError($"错误.texture == null.....{assetPath}");
            return;
        }
        var platformSetting = new TextureImporterPlatformSettings(); //用来单独设置单独的平台信息
        platformSetting.name = "Android"; //平台名字
        platformSetting.format = isASTC? TextureImporterFormat.ASTC_8x8: TextureImporterFormat.ETC2_RGBA8; //Format属性
        platformSetting.overridden = true; //True为勾选Override选项
        platformSetting.maxTextureSize = 8192; //最大纹理尺寸
        texture.SetPlatformTextureSettings(platformSetting); //将平台信息设置给图片

        var platformSettingIP = new TextureImporterPlatformSettings();
        platformSettingIP.name = "iPhone";
        platformSettingIP.format = isASTC? TextureImporterFormat.ASTC_8x8: TextureImporterFormat.PVRTC_RGBA2; //Format属性
        platformSettingIP.overridden = true;
        platformSettingIP.maxTextureSize = 8192;
        texture.SetPlatformTextureSettings(platformSettingIP);

        var platformSettingStandalone = new TextureImporterPlatformSettings();
        platformSettingStandalone.name = "Standalone";
        platformSettingStandalone.format = TextureImporterFormat.DXT5; //Format属性
        platformSettingStandalone.overridden = true;
        platformSettingStandalone.maxTextureSize = 8192;
        texture.SetPlatformTextureSettings(platformSettingStandalone);

        AssetDatabase.ImportAsset(assetPath);
    }
}
#endif
